package com.hpeu_01.day0112.homework;

import com.hpeu_01.day0108.homework.Test;

public class TestThrow {
    public static void main(String[] args) {
        TestThrow testThrow = new TestThrow();
        try {
            testThrow.throwException(10);
        } catch (NullPointerException e) {
            System.out.println(e.getMessage());
        } catch (ClassCastException e) {
            System.out.println(e.getMessage());
        }
    }
    public void throwException(int n ) throws NullPointerException, ClassCastException {
        if (n==0){
            throw new NullPointerException("输入为0！");
        }else {
            throw new ClassCastException("类型转换出错");
        }

    }
}
class NullPointerException extends Exception{

    private static final long serialVersionUID = 815301067611901275L;
    private String message;

    public NullPointerException(String message) {
        this.message = message;
    }

    @Override
    public String getMessage() {
        return message;
    }
}

class ClassCastException extends Exception{

    private static final long serialVersionUID = 3675007352466501391L;
    private String message;

    public ClassCastException(String message) {
        this.message = message;
    }

    @Override
    public String getMessage() {
        return message;
    }
}
